<%@page import="classes.AccountManager"%>
<%@page import="java.io.IOException"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>

<%
	Map<String, String[]> map = request.getParameterMap();
	
	Iterator<String> iter = map.keySet().iterator();
	boolean empty = false;
	while(iter.hasNext()){
		String key = iter.next();
		String[] value = map.get(key);
		if(value[0].equals("")){
		out.println(key + " field cant be empty  <br>");
		empty = true;
		}
	}
	if(empty){
		out.println("<a href=\"addUser.html\">fill again</a>");
	}
	else{
		AccountManager accManager = (AccountManager)application.getAttribute(AccountManager.ACCOUNTMANAGER);
		String username = request.getParameter("username");
		if(accManager.isValidUserName(username)){
			out.println("username: " + username + " is already added. add another one or go home.");
			out.println("<br>");
			out.println("<a href=\"addUser.html\">add another user</a>");
			out.println("<br>");
			out.println("<a href=\"adminLogin.jsp\">go to home page</a>");
		}
		else{
			boolean created = accManager.createAccount(username, request.getParameter("name"), 
										request.getParameter("surname"), request.getParameter("status"), 
										request.getParameter("info"), request.getParameter("pic"));
			if(created){
				out.println(username + " added");
				out.println("<br>");
				out.println("<a href=\"addUser.html\">add another user</a>");
				out.println("<br>");
				out.println("<a href=\"adminLogin.jsp\">go to home page</a>");
			}
			else{
				out.println("user not added for some unknown reason, please try again.");
				out.println("<br>");
				out.println("<a href=\"addUser.html\">fill again</a>");		
			}
		}
	}
		
%>



</body>
</html>